package com.oocl.customer.servlet;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.ConnectException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.customersystem.dto.Food;
import com.oocl.customersystem.dto.MUser;
import com.oocl.customersystem.dto.MUserFoodList;
import com.oocl.customersystem.util.RequestUtil;

/**
 * Servlet implementation class LookOverFoodsByMerchant
 */
public class ShowFoodsByMerchant extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public ShowFoodsByMerchant() {
        super();
       
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String uri="http://ZHA-ITA092-W7:8089/merchantv2/foodlist2c";      //向M端发送拿菜品消息
	
		String mId=request.getParameter("mid");
		mId="mid="+mId;
		
		try {
			MUserFoodList mufl=(MUserFoodList)RequestUtil.request(uri, "POST", mId, MUserFoodList.class);
			
			request.setAttribute("mufl", mufl);
			
			
			request.getRequestDispatcher("showFoodByMerchant.jsp").forward(request, response);
			
			
//			response.setContentType("application/json; charset=utf-8"); 				
//			response.setHeader("Access-Control-Allow-Origin", "*");
//			
//			response.getWriter().write(RequestUtil.wrapToJson(mufl));
			
		} catch (ConnectException e) {			
			response.sendRedirect("error.jsp");
		}
		catch (FileNotFoundException e) {
			response.sendRedirect("error.jsp");
		}
		
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
